
#include <stdio.h>
#include <BSoftBody>

#include <BCube>
#include "ISoftRigidAlgorithm.h"
#include "IContinuousConvexCast.h"
#include "member_BMesh.h"
#include "member_BBody.h"
#include "member_BNode.h"

using namespace BWE;

ISoftRigidAlgorithm::ISoftRigidAlgorithm()
{

}
ISoftRigidAlgorithm::~ISoftRigidAlgorithm()
{

}

void ISoftRigidAlgorithm::caculate()
{
	if (dynamic_cast<BSoftBody*>(_bodyB))
	{
		this->swap();
	}
	BSoftBody* softBody = (BSoftBody*)_bodyA;
	softBody->collisionHandler(_bodyB, _shapeB, _matrixB);
}
void ISoftRigidAlgorithm::timeImpact()
{
	if (dynamic_cast<BSoftBody*>(_bodyB))
	{
		this->swap();
	}

	const BMatrix& matrixA = node_member(_bodyA)->matrix;
	const BMatrix& matrixB = node_member(_bodyB)->matrix;

	const BMatrix& interpMatrixA = body_member(_bodyA)->predictedMatrix;
	const BMatrix& interpMatrixB = body_member(_bodyB)->predictedMatrix;

	CastResult caseResult;
	IContinuousConvexCast ccc(_shapeA, _shapeB);
	ccc.calcTimeOfImpact(matrixA, interpMatrixA, matrixB, interpMatrixB, caseResult);
}
